# encoding:utf-8
# 增加 sim
# author yeyi
import requests
import csv

url = "http://10.2.1.9/gq-bss/v1/bss/sim/add"
headers = {
    'Content-Type': "application/json"
}

with open("tce_bind_car.csv", "w") as csvfile:
    writer = csv.writer(csvfile)
    # 输出导入的人车关系表格title
    writer.writerow(["iccid", "msisdn", "imsi"])
    iccid = range(91000100000, 91000100099)
    # 手机号
    msisdn = range(15157910000, 15157910099)
    imsi = range(400024985000000, 400024985000099)
    for (icc, phone, ims) in zip(iccid, msisdn, imsi):
        print(icc, phone, ims)
        pre = '8YY602C99'
        payload = "{\n" +\
            "    \"iccid\":\""+pre+str(icc)+"\",\n" +\
            "    \"msisdn\":\""+str(phone)+"\",\n" +\
            "    \"imsi\":\""+str(ims)+"\",\n" +\
            "    \"operator\":\"中国联通\",\n" +\
            "    \"type\":3\n" +\
            "}"
        print(payload)
        response = requests.request(
            "POST", url, data=payload.encode('utf-8'), headers=headers)
        print(str(response.content))
        writer.writerow(["1", str(icc), str(phone), str(ims)])
